﻿namespace GuessTheAnswer.Presenter;


/// <summary>
/// 作答
/// </summary>
public class Answer : IRound
{
    /// <summary>
    /// 答题模板
    /// </summary>
    protected AnswerTemplate Template { get; }
    
    /// <summary>
    /// 所有回合
    /// </summary>
    protected List<IAnswerRound> Rounds { get; } = new();


    /// <summary>
    /// 所有题目
    /// </summary>
    protected ISubject[] Subjects => Template.Subjects;




    /// <summary>
    /// 用模板初始化
    /// </summary>
    /// <param name="template"></param>
    public Answer(AnswerTemplate template)
    {
        Template = template;

        foreach(var i  in template.Subjects)
        {
            Rounds.Add(i.CreateRound());
        }
    }

    public int RoundNumber { get; private set; } = 0;


    public void Next()
    {
        RoundNumber++;

        foreach (var round in Rounds) round.Next();
    }

    public void Last()
    {
        if(RoundNumber - 1 < 0)
        {
            throw new Exception("小于最小回合数");
        }

        RoundNumber--;

        foreach (var round in Rounds) round.Last();
    }
}